package test2.spider.news.tencent;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import test2.spider.BaseProcessor;

public class MainOtherProcessor extends BaseProcessor {
	
	static String host = "http://finance.qq.com";

	@Override
	public void process(String url, String encoding) {
		System.out.println("发送http请求到--->" + url);
		HttpResponse response = HttpRequest.get(url).timeout(10000).send();
		if(response.statusCode()!=200) {
			throw new RuntimeException("the end");
		}
		String html = response.charset(encoding).bodyText();
		Document doc = Jsoup.parse(html);
		Elements divs = doc.getElementById("listZone").select("div");
		for(Element div : divs) {
			String href = host + div.select("a").attr("href");
			Tencent.threadPool.submit(new Runnable() {
				@Override
				public void run() {
					new DetailProcessor().process(href, "gbk");					
				}
			});
		}
	}

}
